home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: oliva@dcc.unicamp.br (Alexandre Oliva)
- Newsgroups: comp.std.c++
- Subject: Re: Semantics of "new foo[0]"
- Date: 28 Feb 1996 16:16:43 GMT
- Organization: DCC - UNICAMP - Campinas, SP, Brazil
- Sender: oliva@grande.dcc.unicamp.br
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <orag23j2kn.fsf@grande.dcc.unicamp.br>
- References: <MGB.96Feb27175316@kronecker.mitre.org>
- NNTP-Posting-Host: taumet.eng.sun.com
- Content-Type: text
- X-Nntp-Posting-Host: grande.dcc.unicamp.br
- In-Reply-To: mgb@kronecker.mitre.org's message of 27 Feb 1996 15:13:07 PST
- X-Newsreader: Gnus v5.1
- Content-Length: 1762
- X-Lines: 50
- Originator: clamage@taumet
-
- The ARM is out of date. The September '95 DWP (which is also out of
- date) states:
-
- 3.7.3.1 Allocation functions [basic.stc.dynamic.allocation]
-
- 2 Each [...] allocation shall
- yield a pointer to storage (_intro.memory_) disjoint from any other
- currently allocated storage. The pointer returned points to the start
- (lowest byte address) of the allocated storage. If the size of the
- space requested is zero, the value returned shall be nonzero and shall
- not point to or within any other currently allocated storage. The
- results of dereferencing a pointer returned as a request for zero size
- are undefined.2)
-
- _________________________
- 2) The intent is to have operator new() implementable by calling mal¡
- loc() or calloc(), so the rules are substantially the same. C++ dif¡
- fers from C in requiring a zero request to return a non-null pointer.
-
- G Mike Butler D054 writes:
-
- > According to the ARM section 5.3.3:
- > "operator new() can be called with the argument
- > zero. Repeated such calls return pointers to
- > distinct objects."
-
- > But when I execute the following:
- > #include <isotream.h>
- > main()
- > {
- > struct foo { char a[1024]; };
- > foo *p = new foo[0];
- > foo *q = new foo[0];
-
- > cout << (void *)p << " " << (void *)q << endl;
- > }
-
- > I get
- > 0x338d8 0x338e8
-
- > While these are distinct pointers, the pointers refer to overlapping
- > objects. Is this a legitimate interpretation of section 5.3.3 or is
- > this a compiler/library bug?
-
- > Incidentally, the standard template library included with gcc 2.7.2
- > relies on "operator new(0)" working.
- --
- Alexandre Oliva
- oliva@dcc.unicamp.br
- Universidade Estadual de Campinas, S~ao Paulo, Brasil
-
-
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-